package com.wuxin.result;


import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: jinrongxiangmu
 * @ClassName Result
 * @description:
 * @author: 李尧坤
 * @create: 2025−01-13 20:35
 * @Version 1.0
 **/
@Data
public class Result {

    private Integer code;//code码
    private String message;//信息

    //数据
    private Map<String,Object> data  = new HashMap<>();

    private Result() {
    }

    public static  Result ok(){
        Result r = new Result();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setMessage(ResponseEnum.SUCCESS.getMessage());
        return r;
    }

    public static  Result error(){
        Result r = new Result();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMessage(ResponseEnum.ERROR.getMessage());
        return r;
    }

    //设置特定的结果
    public static  Result setResult(ResponseEnum responseEnum){
        Result r = new Result();
        r.setCode(responseEnum.getCode());
        r.setMessage(responseEnum.getMessage());
        return r;
    }

    //设置消息
    public Result message(String message){
        this.setMessage(message);
        return this;
    }

    public Result code(Integer code){
        this.setCode(code);
        return this;
    }

    public Result data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

    public Result data(Map<String,Object> map){
        this.setData(map);
        return this;
    }


}
